package org.jcc.servlet.encoding.page.bom;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/encoding/page/bom/utf8")
public class EncodingBomUTF8 extends HttpServlet {
    
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setHeader("Content-type", "text/html;charset=gbk"); // 干扰因素 gbk
		ServletOutputStream os = response.getOutputStream();
		String bom = "\uFEFF";// UTF-8 byte order mark (EF BB BF)
		String meta = "<head><meta charset=\"iso-8859-1\"></head>"; // 干扰因素 iso-8859-1
		String contentWithBom = bom + meta + "编码与 header 及 meta 均冲突，UTF-8 BOM 应具有最高优先级。";
		os.write(contentWithBom.getBytes("utf-8")); // 带 bom 的 utf-8
	}

	private static final long serialVersionUID = 1L;
}
